package org.template.example;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "bar")
public class Bar {

  @Id
  @GeneratedValue(strategy = IDENTITY)
  @Column(name = "BAR_ID", unique = true, nullable = false)
  long barId;

  @OneToOne(fetch = FetchType.LAZY, mappedBy = "bar", cascade = CascadeType.ALL)
  BarDetails barDetails;

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "bar")
  Set<Customer> customers;

  @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  @JoinTable(name = "BAR_BEER", joinColumns = { @JoinColumn(name = "BAR_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "BEER_ID", nullable = false, updatable = false) })
  Set<Beer> beers;

  @Column(name = "BAR_NAME", unique = true, nullable = false, length = 128)
  private String barName;

  public Bar() {
  }

  public long getBarId() {
    return barId;
  }

  public void setBarId(long barId) {
    this.barId = barId;
  }

  public BarDetails getBarDetails() {
    return barDetails;
  }

  public void setBarDetails(BarDetails barDetails) {
    this.barDetails = barDetails;
  }

  public Set<Customer> getCustomers() {
    return customers;
  }

  public void setCustomers(Set<Customer> customers) {
    this.customers = customers;
  }

  public Set<Beer> getBeers() {
    return beers;
  }

  public void setBeers(Set<Beer> beers) {
    this.beers = beers;
  }

  public String getBarName() {
    return barName;
  }

  public void setBarName(String barName) {
    this.barName = barName;
  }
}
